package de.teamgamma.cansat.groundstation.livestream;

import java.io.File;
import java.util.ArrayList;

import javax.swing.JMenuBar;

import de.szut.gui.options.Options;
import de.szut.gui.options.OptionsComponent;
import de.teamgamma.cansat.groundstation.main.DefaultPanel;

/**
 * Menubar on the LivestreamPanel
 * @author Marc Huisinga
 *
 */
public class LivestreamMenuBar extends JMenuBar {

	private static final long serialVersionUID = 1766143030078697362L;
	
	private AxisMenu xAxis;
	private AxisMenu yAxis;
	private LivestreamPanel panel;
	private ArrayList<OptionsComponent> optionComponents;
	private Options livestreamOptions;

	/**
	 * 
	 * @param panel - related LivestreamPanel
	 */
	public LivestreamMenuBar(LivestreamPanel panel) {
		this.panel = panel;
		optionComponents = new ArrayList<OptionsComponent>();
		livestreamOptions = new Options();
		livestreamOptions.setOptionsFile(new File("cfg/livestream.cfg"));
		
		setBounds(0, DefaultPanel.HEADERY+7, 120, DefaultPanel.HEADERHEIGHT-10);
		
		xAxis = new AxisMenu(this.panel,"x");
		optionComponents.addAll(xAxis.getOptionComponents());
		add(xAxis);
		
		yAxis = new AxisMenu(this.panel,"y");
		optionComponents.addAll(yAxis.getOptionComponents());
		add(yAxis);
		
		loadStates();
		
		if (!xAxis.containsSelectedButtons()) {
			xAxis.getAxisButtons().get(0).setSelected(true);
		}
		if (!yAxis.containsSelectedButtons()) {
			yAxis.getAxisButtons().get(0).setSelected(true);
		}
	}
	
	/**
	 * Saves the states of all option components on this menu bar
	 */
	public void saveStates() {
		livestreamOptions.saveOptions(optionComponents);
	}
	
	/**
	 * Loads the states of all option components on this menu bar
	 */
	public void loadStates() {
		livestreamOptions.loadOptions(optionComponents);
	}
	
	/**
	 * Gets the X-AxisMenu
	 * @return X-AxisMenu
	 */
	public AxisMenu getxAxis() {
		return xAxis;
	}

	/**
	 * Sets the X-AxisMenu
	 * @param xAxis - X-AxisMenu
	 */
	public void setxAxis(AxisMenu xAxis) {
		this.xAxis = xAxis;
	}

	/**
	 * Gets the Y-AxisMenu
	 * @return Y-AxisMenu
	 */
	public AxisMenu getyAxis() {
		return yAxis;
	}

	/**
	 * Sets the Y-AxisMenu
	 * @param yAxis - Y-AxisMenu
	 */
	public void setyAxis(AxisMenu yAxis) {
		this.yAxis = yAxis;
	}
	
	/**
	 * Gets the options of this menu bar
	 * @return options
	 */
	public Options getLivestreamOptions() {
		return livestreamOptions;
	}

	/**
	 * Sets the options of this menu bar
	 * @param livestreamOptions
	 */
	public void setLivestreamOptions(Options livestreamOptions) {
		this.livestreamOptions = livestreamOptions;
	}
}
